import logging
import multiprocessing
import time


LOG_FMT = '%(asctime)s %(levelname)s [%(name)s] [%(threadName)s] %(message)s'
logging.basicConfig(level=logging.DEBUG, format=LOG_FMT)


def main():
    from socket_http_client import main as _client
    from socket_http_server import main as _server

    is_ready = multiprocessing.Value('b', False)
    running = multiprocessing.Value('b', True)

    p_s = multiprocessing.Process(target=_server, args=(is_ready, running))
    p_c = multiprocessing.Process(target=_client)

    p_s.start()

    while True:
        time.sleep(1)
        if is_ready.value:
            break

    p_c.start()
    p_c.join()
    # p_s.terminate()
    running.value = False
    p_s.join()


if __name__ == '__main__':
    main()
